package cn.dnf.org.service.impl;

import cn.dnf.basic.service.impl.BaseServiceImpl;
import cn.dnf.basic.util.PageList;
import cn.dnf.org.domain.Employee;
import cn.dnf.org.mapper.DepartmentMapper;
import cn.dnf.org.mapper.EmployeeMapper;
import cn.dnf.org.query.EmployeeQuery;
import cn.dnf.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
//父类有事务,该注解有继承性
//@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public void save(Employee employee) {
        employeeMapper.save(employee); //返回自增的主键

        //保存中间表
        employeeMapper.saveEmployeeRole(employee.getId(),employee.getRole_id());
    }

    @Override
    public void update(Employee employee) {
        employeeMapper.update(employee);

    }

    @Override
    public void remove(Long eid) {
        //先删除t_employee_role
        employeeMapper.removeEmployeeRole(eid);
        
        employeeMapper.remove(eid);
    }

    @Override
    public List<Employee> findByShopId(Long shopId) {
        return employeeMapper.findByShopId(shopId);
    }
}
